package net.adetech.crj.web;

import net.adetech.crj.entity.Announcement;
import net.adetech.crj.utils.ServiceUtil;
import net.adetech.framework.entity.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AnnouncementWebController {

    @Autowired
    ServiceUtil serviceUtil;

    private static Map<String,String> typeNameMap = new HashMap<String, String>();
    static {
        typeNameMap.put("2","公告通知");
        typeNameMap.put("1","办事指南");
        typeNameMap.put("3","温馨提示");
        typeNameMap.put("4","定居公示");
        typeNameMap.put("12","公告通知");
        typeNameMap.put("11","办事指南");
        typeNameMap.put("13","温馨提示");
    }


    @RequestMapping("/announcement/list/page")
    public String announcementList(String type,Model model)
    {

        ServiceResponse response = serviceUtil.callService("announcement.getListByType","type",type);
        List<Announcement> announcementList = (List<Announcement>)response.getResults().get("announcementList");
        String typeName  = typeNameMap.get(type);
        model.addAttribute("list",announcementList);
        model.addAttribute("typeName",typeName);
        return  "announcementList";
    }

    @RequestMapping("/announcement/detail/page")
    public String announcementDetail(String id,Model model)
    {

        ServiceResponse response = serviceUtil.callService("announcement.getById","id",id);
        Announcement announcement = (Announcement)response.getResults().get("announcement");
        model.addAttribute("a",announcement);
        return  "announcementDetail";
    }

}
